package com.pureut.order.service.impl;

import com.pureut.order.dto.WorkbenchManagerDataDto;
import com.pureut.order.service.PurchaseOrderService;
import com.pureut.order.service.SalesOrderService;
import com.pureut.order.service.WorkbenchService;
import com.sale.common.core.domain.R;
import com.sale.goods.api.RemoteGoodsCollectionService;
import com.sale.goods.api.RemoteGoodsPaymentService;
import lombok.RequiredArgsConstructor;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;

/**
 * 首页工作台实现层
 */
@RequiredArgsConstructor
@Service
public class WorkbenchServiceImpl implements WorkbenchService {

    private final SalesOrderService salesOrderService;

    private final PurchaseOrderService purchaseOrderService;

    @DubboReference
    RemoteGoodsCollectionService remoteGoodsCollectionService;

    @DubboReference
    RemoteGoodsPaymentService remoteGoodsPaymentService;


    /**
     * 首页工作台(管理)上方数据接口
     */
    @Override
    public WorkbenchManagerDataDto getWorkbenchManagerData() {
        WorkbenchManagerDataDto workbenchManagerDataDto = new WorkbenchManagerDataDto();
        //销售订单金额
        String saleOrderPrice = salesOrderService.getSaleOrderPrice();
        //采购订单金额
        String purchaseOrderPrice = purchaseOrderService.getPurchaseOrderPrice();
        //销售订单数
        String saleOrderNum = salesOrderService.getSaleOrderNum();
        //采购订单数
        String purchaseOrderNum = purchaseOrderService.getPurchaseOrderNum();
        //销售已收款金额
        String saleReceived = remoteGoodsCollectionService.received();
        //客户欠款金额
        String arrears = remoteGoodsCollectionService.arrears();
        //采购已付款金额
        String purchaseReceived = remoteGoodsPaymentService.received();
        //采购未付款金额
        String purchaseArrears = remoteGoodsPaymentService.arrears();
        workbenchManagerDataDto
            .setSaleOrderAmount(saleOrderPrice)
            .setPurchaseOrderAmount(purchaseOrderPrice)
            .setSaleOrderNum(saleOrderNum)
            .setPurchaseOrderNum(purchaseOrderNum)
            .setSalePaymentReceived(saleReceived)
            .setCustomerArrears(arrears)
            .setPurchasePaymentReceived(purchaseReceived)
            .setPurchaseNoPayment(purchaseArrears);
        return workbenchManagerDataDto;
    }
}
